package com.makeblock.demo.testdatabinding.viewmodel;

import android.content.Intent;
import android.databinding.BaseObservable;
import android.databinding.Bindable;
import android.view.View;
import android.widget.CompoundButton;

import com.makeblock.demo.testdatabinding.BR;
import com.makeblock.demo.testdatabinding.list.RecyclerViewActivity;
import com.makeblock.demo.testdatabinding.model.DataModel;


/**
 * Created by xuexin on 2016/10/26.
 */

public class MainViewModel extends BaseObservable {

    private DataModel model;

    public MainViewModel(DataModel dataModel) {
        super();
        model = dataModel;
    }

    @Bindable
    public boolean getShow() {
        return model.getShow();
    }

    @Bindable
    public String getText() {
        return model.getText();
    }

    @Bindable
    public int getPosition() {
        return (int) (Math.random() * 1000);
    }

    public String getHideText() {
        return model.getHideString();
    }

    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        model.setShow(isChecked);
        notifyPropertyChanged(BR.show);
        if (isChecked) {
            model.setText("显示");
        } else {
            model.setText("隐藏");
        }
        notifyPropertyChanged(BR.text);
    }

    public boolean onLongClick(View v) {
        model.setShow(!model.getShow());
        notifyPropertyChanged(BR.show);
        notifyPropertyChanged(BR.position);
        return true;
    }

    public void jumpToNextActivity(View view) {
        view.getContext().startActivity(new Intent(view.getContext(), RecyclerViewActivity.class));
    }



}
